using DealerPlatform.Domain;
using DealerPlatform.Service.ShoppingCartApp.Dtos;

namespace DealerPlatform.Service.OrderApp;

public partial class OrderService
{
    private async Task AddOrderDetail(List<ShoppingCartDto> carts,
        string customerNo,
        string orderNo,
        DateTime inputDate)
    {
        foreach (var cart in carts)
        {
            SaleOrderDetail detail = new()
            {
                SaleOrderGuid = Guid.NewGuid().ToString(),
                SaleOrderNo = orderNo,
                ProductNo = cart.ProductNo,
                ProductName = cart.ProductDto.ProductName,
                ProductPhotoUrl = cart.ProductDto.ProductPhoto?.ProductPhotoUrl,
                CustomerNo = customerNo,
                InputDate = inputDate,
                OrderNum = cart.ProductNum,
                BasePrice = cart.ProductDto.ProductSale?.SalePrice ?? 0,
                DiffPrice = 0,
                SalePrice = cart.ProductDto.ProductSale?.SalePrice ?? 0
            };
            await saleOrderDetailRepository.InsertAsync(detail);
        }
    }

    private async Task<List<SaleOrderDetail>> GetOrderDetailsByOrderNos(params string[] orderNos)
    {
        return await saleOrderDetailRepository.GetListAsync(m => orderNos.Contains(m.SaleOrderNo));
    }
}